package com.ruoyi.bussiness.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bussiness.domain.TraLesson;
import com.ruoyi.bussiness.service.ITraLessonService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训课时Controller
 * 
 * @author ruoyi
 * @date 2023-11-12
 */
@Controller
@RequestMapping("/bussiness/lesson")
public class TraLessonController extends BaseController
{
    private String prefix = "bussiness/lesson";

    @Autowired
    private ITraLessonService traLessonService;

    @RequiresPermissions("bussiness:lesson:view")
    @GetMapping()
    public String lesson()
    {
        return prefix + "/lesson";
    }

    /**
     * 查询培训课时列表
     */
    @RequiresPermissions("bussiness:lesson:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TraLesson traLesson)
    {
        startPage();
        List<TraLesson> list = traLessonService.selectTraLessonList(traLesson);
        return getDataTable(list);
    }

    /**
     * 导出培训课时列表
     */
    @RequiresPermissions("bussiness:lesson:export")
    @Log(title = "培训课时", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TraLesson traLesson)
    {
        List<TraLesson> list = traLessonService.selectTraLessonList(traLesson);
        ExcelUtil<TraLesson> util = new ExcelUtil<TraLesson>(TraLesson.class);
        return util.exportExcel(list, "培训课时数据");
    }

    /**
     * 新增培训课时
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存培训课时
     */
    @RequiresPermissions("bussiness:lesson:add")
    @Log(title = "培训课时", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TraLesson traLesson)
    {
        return toAjax(traLessonService.insertTraLesson(traLesson));
    }

    /**
     * 修改培训课时
     */
    @RequiresPermissions("bussiness:lesson:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TraLesson traLesson = traLessonService.selectTraLessonById(id);
        mmap.put("traLesson", traLesson);
        return prefix + "/edit";
    }

    /**
     * 修改保存培训课时
     */
    @RequiresPermissions("bussiness:lesson:edit")
    @Log(title = "培训课时", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TraLesson traLesson)
    {
        return toAjax(traLessonService.updateTraLesson(traLesson));
    }

    /**
     * 删除培训课时
     */
    @RequiresPermissions("bussiness:lesson:remove")
    @Log(title = "培训课时", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(traLessonService.deleteTraLessonByIds(ids));
    }
}
